﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MethodWorx.CMS.Content;
using MethodWorx.CMS.Services;
using MethodWorx.CMS.TemplateParser.Installer;
using System.IO;
using MethodWorx.CMS.Membership;

namespace MethodWorx.CMS.UI.Models
{
    public class ContentModel
    {
        private ContentService content;
        private InstallerEngine[] macros;

        public ContentModel(ContentService content, string [] files, User user)
        {
            this.content = content;
            this.RootPage = content.GetRootPage();

            List<InstallerEngine> macros = new List<InstallerEngine>();

            foreach(string file in files)
            {
                using(var s = File.Open(file, FileMode.Open, FileAccess.Read))
                {
                    macros.Add(new InstallerEngine(file, s, user));
                }
            }

            this.macros = macros.ToArray();
        }

        public Page RootPage { get; private set; }


        public InstallerEngine[] Macros
        {
            get
            {
                return this.macros;
            }
        }
    }
}